package org.myself.meeting.controller;

import org.myself.meeting.model.*;
import org.myself.meeting.service.FormeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 杜宇康
 * @create 2021—03-21 18:52
 */
@Controller
@RequestMapping("/forme")
public class FormeController {

    @Autowired
    FormeService formeService;

    @RequestMapping("/add")
    @ResponseBody
    public Result addForme(@RequestBody Formepublish forme){
        int i = formeService.addForme(forme);
        if(i>=1){
            return new Result(200,"新建成功",null);
        }else{
            return new Result(400,"新建失败",null);
        }
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Result deleteForme(@RequestBody FormeDeleteAcc acc){
        int i = formeService.deleteForme(acc.getPublishid());
        if(i>=0){
            return new Result(200,"删除成功",null);
        }else{
            return new Result(400,"删除失败",null);
        }

    }

    @RequestMapping("/update")
    @ResponseBody
    public Result updateForme(@RequestBody Formepublish forme){
        int i = formeService.updateForme(forme);
        if(i>=0){
            return new Result(200,"更新成功",null);
        }else{
            return new Result(400,"更新失败",null);
        }
    }

    @RequestMapping("/selectall")
    @ResponseBody
    public Result selectAllForme(@RequestBody FormeSelectPageAcc acc){
        List<Formepublish> list = formeService.selectAll(acc.getPages());
        Integer cou = formeService.selectcount();

        Integer i;
        if(cou==0||cou==null){
            i =0;
        }else{
            i=cou/10;
            if(cou%10>0){
                i++;
            }
        }
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("list",list);
        map.put("page",acc.getPages());
        map.put("pages",i);
        return new Result(200,"查询成功",map);
    }


    @RequestMapping("/adddiscuss")
    @ResponseBody
    public Result addFormediscuss(@RequestBody Fromeback back){
        int i;
        if(back.getBackname()==null){
            i = formeService.addFormedisac(back);
        }else{
            i = formeService.addFormedis(back);
        }

        if(i>=1){
            return new Result(200,"新建成功",null);
        }else{
            return new Result(400,"新建失败",null);
        }
    }

    @RequestMapping("/deletediscuss")
    @ResponseBody
    public Result deleteFormediscuss(@RequestBody FormedeletediscussAcc acc){
        int i = formeService.deleteFormedis(acc.getDiscussid());
        if(i>=0){
            return new Result(200,"删除成功",null);
        }else{
            return new Result(400,"删除失败",null);
        }

    }


    @RequestMapping("/selectalldiscuss")
    @ResponseBody
    public Result selectAllFormediscuss(@RequestBody FormeselectalldiscussAcc acc){
        List<List<Fromebackinfo>> list = formeService.selectAlldis(acc.getPublishid(), acc.getPages());
        Integer cou = formeService.selectcondis(acc.getPublishid());
        Integer i;
        if(cou==0||cou==null){
            i =0;
        }else{
            i=cou/5;
            if(cou%5>0){
                i++;
            }
        }
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("list",list);
        map.put("page",acc.getPages());
        map.put("pages",i);
        return new Result(200,"查询成功",map);
    }

}
